<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.5">
<meta name="author" content="2019-08-08 13:15:33 CEST">
<title>N4JS Language Specification</title>
<link rel="stylesheet" href="styles/spec.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<!-- ************* docinfo ******************************************************************* -->


<!-- ************* Favicon ************-->
<link rel="icon" href="images/favicon.ico" />

<!-- ************* Back-to-top JQuery ************* -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>


<link href="styles/prism.min.css" rel="stylesheet" />
<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

<!-- ************* Styles ************* -->
<link rel="stylesheet" type="text/css" href="styles/n4jsspec-adoc.css">


<!-- ****************** NavBar ****************** -->
<div id="menubar">
	<div class="banner">
        <a href="https://www.eclipse.org/n4js/#"><img id="logo" src="images/n4js-logo.png" alt="Eclipse N4JS"></a>
    </div>
<ul>
  <li><a href="index.html">Index</a></li>
</ul>
</div>
<!-- ************* docinfo ******************************************************************* -->
<style>
      .admonitionblock td.icon .icon-todo:before{content:"\f249";color:#f4ee42}
    </style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>N4JS Language Specification</h1>
<div class="details">
<span id="author" class="author">2019-08-08 13:15:33 CEST</span><br>
<span id="revnumber">version 0.9</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="introduction.html#_introduction">1. Introduction</a>
<ul class="sectlevel2">
<li><a href="introduction.html#_notation">1.1. Notation</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_grammar-notation">1.1.1. Grammar Notation</a></li>
<li><a href="introduction.html#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></li>
<li><a href="introduction.html#_types-of-an-element">1.1.2.2. Types of an Element</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="introduction.html#_auxiliary-functions">1.2. Auxiliary Functions</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_binding">1.2.1. Binding</a></li>
<li><a href="introduction.html#_merging-types">1.2.2. Merging Types</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_logic-formulas">1.2.2.1. Logic Formulas</a></li>
</ul>
</li>
<li><a href="introduction.html#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="grammar.html#_grammar">2. Grammar</a>
<ul class="sectlevel2">
<li><a href="grammar.html#_lexical-conventions">2.1. Lexical Conventions</a>
<ul class="sectlevel3">
<li><a href="grammar.html#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></li>
<li><a href="grammar.html#_this-keyword">2.1.2. This Keyword</a></li>
<li><a href="grammar.html#_regular-expression-literals">2.1.3. Regular Expression Literals</a></li>
<li><a href="grammar.html#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></li>
<li><a href="grammar.html#_jsdoc">2.1.5. JSDoc</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="names.html#_names">3. Names</a>
<ul class="sectlevel2">
<li><a href="names.html#_access-control">3.1. Access Control</a></li>
<li><a href="names.html#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a>
<ul class="sectlevel3">
<li><a href="names.html#_accessibility-of-members">3.2.1. Accessibility of Members</a></li>
<li><a href="names.html#_valid-names">3.2.2. Valid Names</a></li>
<li><a href="names.html#_qualified-names">3.2.3. Qualified Names</a></li>
<li><a href="names.html#_name-duplicates">3.2.4. Name Duplicates</a>
<ul class="sectlevel4">
<li><a href="names.html#_lexical-environment">3.2.4.1. Lexical Environment</a></li>
<li><a href="names.html#_duplicates-and-shadowing">3.2.4.2. Duplicates and Shadowing</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_types">4. Types</a>
<ul class="sectlevel2">
<li><a href="types.html#_overview">4.1. Overview</a></li>
<li><a href="types.html#_type-expressions">4.2. Type Expressions</a>
<ul class="sectlevel3">
<li><a href="types.html#_syntax">4.2.1. Syntax</a></li>
<li><a href="types.html#_properties">4.2.2. Properties</a></li>
<li><a href="types.html#_semantics">4.2.3. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_type-inference">4.3. Type Inference</a></li>
<li><a href="types.html#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_generic-types">4.4.1. Generic Types</a></li>
<li><a href="types.html#_type-variables">4.4.2. Type Variables</a></li>
<li><a href="types.html#_parameterized-types">4.4.3. Parameterized Types</a></li>
</ul>
</li>
<li><a href="types.html#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_undefined-type">4.5.1. Undefined Type</a></li>
<li><a href="types.html#_null-type">4.5.2. Null Type</a></li>
<li><a href="types.html#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></li>
<li><a href="types.html#_primitive-string-type">4.5.4. Primitive String Type</a></li>
<li><a href="types.html#_primitive-number-type">4.5.5. Primitive Number Type</a></li>
<li><a href="types.html#_primitive-type-int">4.5.6. Primitive Type int</a></li>
<li><a href="types.html#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></li>
</ul>
</li>
<li><a href="types.html#_primitive-n4js-types">4.6. Primitive N4JS Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_any-type">4.6.1. Any Type</a>
<ul class="sectlevel4">
<li><a href="types.html#any-type-semantics">4.6.1.1. Semantics</a></li>
<li><a href="types.html#any-type-type-inference">4.6.1.2. Type Inference</a>
<ul class="sectlevel5">
<li><a href="types.html#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_void-type">4.6.2. Void Type</a>
<ul class="sectlevel4">
<li><a href="types.html#void-type-semantics">4.6.2.1. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_unknown-type">4.6.3. Unknown Type</a></li>
<li><a href="types.html#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a>
<ul class="sectlevel4">
<li><a href="types.html#pathselector-semantics">4.6.4.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a>
<ul class="sectlevel3">
<li><a href="types.html#ECMAScript-objects-semantics">4.7.1. Semantics</a></li>
<li><a href="types.html#_object-type">4.7.2. Object Type</a></li>
<li><a href="types.html#_function-object-type">4.7.3. Function-Object-Type</a></li>
<li><a href="types.html#_array-object-type">4.7.4. Array Object Type</a></li>
<li><a href="types.html#_string-object-type">4.7.5. String Object Type</a></li>
<li><a href="types.html#_boolean-object-type">4.7.6. Boolean Object Type</a></li>
<li><a href="types.html#_number-object-type">4.7.7. Number Object Type</a></li>
<li><a href="types.html#_global-object-type">4.7.8. Global Object Type</a></li>
<li><a href="types.html#_symbol">4.7.9. Symbol</a></li>
<li><a href="types.html#_promise">4.7.10. Promise</a></li>
<li><a href="types.html#_iterator-interface">4.7.11. Iterator Interface</a></li>
<li><a href="types.html#_iterable-interface">4.7.12. Iterable Interface</a></li>
</ul>
</li>
<li><a href="types.html#_built-in-n4js-types">4.8. Built-In N4JS Types</a>
<ul class="sectlevel3">
<li><a href="types.html#_n4object">4.8.1. N4Object</a>
<ul class="sectlevel4">
<li><a href="types.html#N4Object-semantics">4.8.1.1. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_n4class">4.8.2. N4Class</a></li>
<li><a href="types.html#IterableN">4.8.3. IterableN</a></li>
</ul>
</li>
<li><a href="types.html#_type-modifiers">4.9. Type Modifiers</a>
<ul class="sectlevel3">
<li><a href="types.html#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></li>
<li><a href="types.html#_optional-return-types">4.9.2. Optional Return Types</a></li>
</ul>
</li>
<li><a href="types.html#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a>
<ul class="sectlevel3">
<li><a href="types.html#_union-type">4.10.1. Union Type</a>
<ul class="sectlevel4">
<li><a href="types.html#union-type-syntax">4.10.1.1. Syntax</a></li>
<li><a href="types.html#union-type-semantics">4.10.1.2. Semantics</a></li>
<li><a href="types.html#_warnings">4.10.1.3. Warnings</a></li>
</ul>
</li>
<li><a href="types.html#_intersection-type">4.10.2. Intersection Type</a>
<ul class="sectlevel4">
<li><a href="types.html#intersection-type-syntax">4.10.2.1. Syntax</a></li>
<li><a href="types.html#intersection-type-semantics">4.10.2.2. Semantics</a></li>
<li><a href="types.html#_warnings-2">4.10.2.3. Warnings</a></li>
</ul>
</li>
<li><a href="types.html#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></li>
<li><a href="types.html#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a>
<ul class="sectlevel4">
<li><a href="types.html#_properties-of-union-type">4.10.4.1. Properties of Union Type</a>
<ul class="sectlevel5">
<li><a href="types.html#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></li>
</ul>
</li>
<li><a href="types.html#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a>
<ul class="sectlevel5">
<li><a href="types.html#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="types.html#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a>
<ul class="sectlevel3">
<li><a href="types.html#_syntax-3">4.11.1. Syntax</a></li>
<li><a href="types.html#_semantics-2">4.11.2. Semantics</a></li>
<li><a href="types.html#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></li>
</ul>
</li>
<li><a href="types.html#_this-type">4.12. This Type</a>
<ul class="sectlevel3">
<li><a href="types.html#this-type-syntax">4.12.1. Syntax</a></li>
<li><a href="types.html#this-keyword-semantics">4.12.2. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_enums">4.13. Enums</a>
<ul class="sectlevel3">
<li><a href="types.html#_enums-n4js">4.13.1. Enums (N4JS)</a>
<ul class="sectlevel4">
<li><a href="types.html#enums-syntax">4.13.1.1. Syntax</a></li>
<li><a href="types.html#enums-semantics">4.13.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="types.html#_string-based-enums">4.13.2. String-Based Enums</a></li>
</ul>
</li>
<li><a href="types.html#_short-hand-syntax">4.14. Short-Hand Syntax</a>
<ul class="sectlevel3">
<li><a href="types.html#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></li>
<li><a href="types.html#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_classifiers">5. Classifiers</a>
<ul class="sectlevel2">
<li><a href="classifiers.html#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_properties-2">5.1.1. Properties</a></li>
<li><a href="classifiers.html#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></li>
<li><a href="classifiers.html#_classes">5.1.3. Classes</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_definition-of-classes">5.1.3.1. Definition of Classes</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#class-syntax">5.1.3.1.1. Syntax</a></li>
<li><a href="classifiers.html#class-properties">5.1.3.1.2. Properties</a></li>
<li><a href="classifiers.html#class-type-inference">5.1.3.1.3. Type Inference</a></li>
</ul>
</li>
<li><a href="classifiers.html#class-semantics">5.1.3.2. Semantics</a></li>
<li><a href="classifiers.html#_final-modifier">5.1.3.3. Final Modifier</a></li>
<li><a href="classifiers.html#_abstract-classes">5.1.3.4. Abstract Classes</a></li>
<li><a href="classifiers.html#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></li>
<li><a href="classifiers.html#_superclass">5.1.3.6. Superclass</a></li>
</ul>
</li>
<li><a href="classifiers.html#_interfaces">5.1.4. Interfaces</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#interfaces-syntax">5.1.4.1.1. Syntax</a></li>
<li><a href="classifiers.html#interfaces-properties">5.1.4.1.2. Properties</a></li>
<li><a href="classifiers.html#interfaces-type-inference">5.1.4.1.3. Type Inference</a></li>
<li><a href="classifiers.html#interfaces-semantics">5.1.4.1.4. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_generic-classifiers">5.1.5. Generic Classifiers</a></li>
<li><a href="classifiers.html#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></li>
</ul>
</li>
<li><a href="classifiers.html#_members">5.2. Members</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_syntax-4">5.2.1. Syntax</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_properties-3">5.2.1.1. Properties</a></li>
</ul>
</li>
<li><a href="classifiers.html#_semantics-3">5.2.2. Semantics</a></li>
<li><a href="classifiers.html#_methods">5.2.3. Methods</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_syntax-5">5.2.3.1. Syntax</a></li>
<li><a href="classifiers.html#_properties-4">5.2.3.2. Properties</a></li>
<li><a href="classifiers.html#_semantics-4">5.2.3.3. Semantics</a></li>
<li><a href="classifiers.html#_final-methods">5.2.3.4. Final Methods</a></li>
<li><a href="classifiers.html#_abstract-methods">5.2.3.5. Abstract Methods</a></li>
<li><a href="classifiers.html#_generic-methods">5.2.3.6. Generic Methods</a></li>
</ul>
</li>
<li><a href="classifiers.html#_default-methods-in-interfaces">5.2.4. Default Methods in Interfaces</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_asynchronous-methods">5.2.4.1. Asynchronous Methods</a></li>
</ul>
</li>
<li><a href="classifiers.html#_constructors">5.2.5. Constructors</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_structural-this-type-in-constructor">5.2.5.1. Structural This Type in Constructor</a></li>
<li><a href="classifiers.html#spec-constructor">5.2.5.2. @Spec Constructor</a></li>
<li><a href="classifiers.html#_callable-constructors">5.2.5.3. Callable Constructors</a></li>
<li><a href="classifiers.html#_covariant-constructors">5.2.5.4. Covariant Constructors</a></li>
</ul>
</li>
<li><a href="classifiers.html#_data-fields">5.2.6. Data Fields</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#data-fields-syntax">5.2.6.1. Syntax</a></li>
<li><a href="classifiers.html#data-fields-properties">5.2.6.2. Properties</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#data-fields-semantics">5.2.6.2.1. Semantics</a></li>
<li><a href="classifiers.html#data-fields-type-inference">5.2.6.2.2. Type Inference</a></li>
</ul>
</li>
<li><a href="classifiers.html#_assignment-modifiers">5.2.6.3. Assignment Modifiers</a></li>
<li><a href="classifiers.html#_field-accessors-getter-setter">5.2.6.4. Field Accessors (Getter/Setter)</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#field-acessors-syntax">5.2.6.4.1. Syntax</a></li>
<li><a href="classifiers.html#field-acessors-properties">5.2.6.4.2. Properties</a></li>
<li><a href="classifiers.html#field-accessors-semantics">5.2.6.4.3. Semantics</a></li>
</ul>
</li>
<li><a href="classifiers.html#optional-fields">5.2.6.5. Optional Fields</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_syntax-6">5.2.6.5.1. Syntax</a></li>
<li><a href="classifiers.html#_semantics-5">5.2.6.5.2. Semantics</a></li>
<li><a href="classifiers.html#_background">5.2.6.5.3. Background</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_static-members">5.2.7. Static Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_access-from-and-to-static-members">5.2.7.1. Access From and To Static Members</a></li>
<li><a href="classifiers.html#_generic-static-methods">5.2.7.2. Generic static methods</a></li>
<li><a href="classifiers.html#_static-members-of-interfaces">5.2.7.3. Static Members of Interfaces</a></li>
</ul>
</li>
<li><a href="classifiers.html#_redefinition-of-members">5.2.8. Redefinition of Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_overriding-of-members">5.2.8.1. Overriding of Members</a></li>
<li><a href="classifiers.html#_implementation-of-members">5.2.8.2. Implementation of Members</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_member-consumption">5.2.8.2.1. Member Consumption</a></li>
<li><a href="classifiers.html#_member-implementation">5.2.8.2.2. Member Implementation</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_structural-typing">5.3. Structural Typing</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_syntax-7">5.3.1. Syntax</a></li>
<li><a href="classifiers.html#_definition-site-structural-typing">5.3.2. Definition Site Structural Typing</a></li>
<li><a href="classifiers.html#_use-site-structural-typing">5.3.3. Use-Site Structural Typing</a></li>
<li><a href="classifiers.html#structural-readWriteInit-field-typing">5.3.4. Structural Read-only, Write-only and Initializer Field Typing</a></li>
<li><a href="classifiers.html#_public-setter-annotated-with-code-providesinitializer-code">5.3.5. Public Setter Annotated With <code>ProvidesInitializer</code></a></li>
<li><a href="classifiers.html#_structural-types-with-optional-fields">5.3.6. Structural Types With Optional Fields</a></li>
<li><a href="classifiers.html#_structural-types-with-access-modifier">5.3.7. Structural Types With Access Modifier</a></li>
<li><a href="classifiers.html#_structural-types-with-additional-members">5.3.8. Structural Types With Additional Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_syntax-8">5.3.8.1. Syntax</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_semantics-6">5.3.8.1.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_functions">6. Functions</a>
<ul class="sectlevel2">
<li><a href="functions.html#_function-type">6.1. Function Type</a>
<ul class="sectlevel3">
<li><a href="functions.html#_properties-5">6.1.1. Properties</a></li>
<li><a href="functions.html#function-type-inference">6.1.2. Type Inference</a></li>
<li><a href="functions.html#_autoboxing-of-function-type">6.1.3. Autoboxing of Function Type</a></li>
<li><a href="functions.html#_arguments-object">6.1.4. Arguments Object</a></li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-5-function-definition">6.2. ECMAScript 5 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_function-declaration">6.2.1. Function Declaration</a>
<ul class="sectlevel4">
<li><a href="functions.html#_syntax-9">6.2.1.1. Syntax</a></li>
<li><a href="functions.html#_semantics-8">6.2.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="functions.html#_function-expression">6.2.2. Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#function-expression-syntax">6.2.2.1. Syntax</a></li>
<li><a href="functions.html#_semantics-and-type-inference">6.2.2.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-2015-function-definition">6.3. ECMAScript 2015 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_formal-parameters">6.3.1. Formal Parameters</a>
<ul class="sectlevel4">
<li><a href="functions.html#Type_Modifiers_Optional">6.3.1.1. Optional Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Default">6.3.1.2. Default Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Variadic">6.3.1.3. Variadic</a></li>
</ul>
</li>
<li><a href="functions.html#_generator-functions">6.3.2. Generator Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#generator-functions-syntax">6.3.2.1. Syntax</a></li>
<li><a href="functions.html#generator-functions-semantics">6.3.2.2. Semantics</a></li>
<li><a href="functions.html#_generator-arrow-functions">6.3.2.3. Generator Arrow Functions</a></li>
</ul>
</li>
<li><a href="functions.html#_arrow-function-expression">6.3.3. Arrow Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#arrow-function-expression-syntax">6.3.3.1. Syntax</a></li>
<li><a href="functions.html#arrow-function-expression-semantics-and-type-inference">6.3.3.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-proposals-function-definition">6.4. ECMAScript Proposals Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_asynchronous-functions">6.4.1. Asynchronous Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#asynchronous-functions-syntax">6.4.1.1. Syntax</a></li>
<li><a href="functions.html#asynchronous-functions-semantics">6.4.1.2. Semantics</a></li>
<li><a href="functions.html#_asynchronous-arrow-functions">6.4.1.3. Asynchronous Arrow Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_n4js-extended-function-definition">6.5. N4JS Extended Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_generic-functions">6.5.1. Generic Functions</a></li>
<li><a href="functions.html#_promisifiable-functions">6.5.2. Promisifiable Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversions-and-reflection">7. Conversions and Reflection</a>
<ul class="sectlevel2">
<li><a href="conversions_and_reflection.html#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_coercing">7.1.1. Coercing</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a>
<ul class="sectlevel4">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_type-cast-and-type-check">7.3. Type Cast and Type Check</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_type-cast">7.3.1. Type Cast</a></li>
<li><a href="conversions_and_reflection.html#_type-check">7.3.2. Type Check</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_reflection-meta-information">7.4. Reflection meta-information</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_reflection-for-classes">7.4.1. Reflection for Classes</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></li>
</ul>
</li>
<li><a href="expressions.html#_expressions">8. Expressions</a>
<ul class="sectlevel2">
<li><a href="expressions.html#_ecmascript-5-expressions">8.1. ECMAScript 5 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-this-literal">8.1.1. The this Literal</a></li>
<li><a href="expressions.html#_identifier">8.1.2. Identifier</a></li>
<li><a href="expressions.html#_literals">8.1.3. Literals</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_integer-literals">8.1.3.1. Integer Literals</a></li>
</ul>
</li>
<li><a href="expressions.html#_array-literal">8.1.4. Array Literal</a></li>
<li><a href="expressions.html#_object-literal">8.1.5. Object Literal</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_properties-6">8.1.5.1. Properties</a></li>
<li><a href="expressions.html#_scoping-and-linking">8.1.5.2. Scoping and linking</a></li>
</ul>
</li>
<li><a href="expressions.html#_parenthesized-expression-and-grouping-operator">8.1.6. Parenthesized Expression and Grouping Operator</a></li>
<li><a href="expressions.html#_property-accessors">8.1.7. Property Accessors</a>
<ul class="sectlevel4">
<li><a href="expressions.html#properties-1">8.1.7.1. Properties</a></li>
</ul>
</li>
<li><a href="expressions.html#_new-expression">8.1.8. New Expression</a></li>
<li><a href="expressions.html#_function-expression-2">8.1.9. Function Expression</a></li>
<li><a href="expressions.html#_function-calls">8.1.10. Function Calls</a></li>
<li><a href="expressions.html#_postfix-expression">8.1.11. Postfix Expression</a></li>
<li><a href="expressions.html#_unary-expression">8.1.12. Unary Expression</a></li>
<li><a href="expressions.html#_multiplicative-expression">8.1.13. Multiplicative Expression</a></li>
<li><a href="expressions.html#_additive-expression">8.1.14. Additive Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#type-inference-10">8.1.14.1. Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#_bitwise-shift-expression">8.1.15. Bitwise Shift Expression</a></li>
<li><a href="expressions.html#_relational-expression">8.1.16. Relational Expression</a></li>
<li><a href="expressions.html#_equality-expression">8.1.17. Equality Expression</a></li>
<li><a href="expressions.html#_binary-bitwise-expression">8.1.18. Binary Bitwise Expression</a></li>
<li><a href="expressions.html#_binary-logical-expression">8.1.19. Binary Logical Expression</a></li>
<li><a href="expressions.html#_conditional-expression">8.1.20. Conditional Expression</a></li>
<li><a href="expressions.html#_assignment-expression">8.1.21. Assignment Expression</a></li>
<li><a href="expressions.html#_comma-expression">8.1.22. Comma Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-6-expressions">8.2. ECMAScript 6 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-super-keyword">8.2.1. The super Keyword</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-7-expressions">8.3. ECMAScript 7 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_await-expression">8.3.1. Await Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_n4js-specific-expressions">8.4. N4JS Specific Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_class-expression">8.4.1. Class Expression</a></li>
<li><a href="expressions.html#_cast-as-expression">8.4.2. Cast (As) Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#cast-as-expression-semantics-type-inference">8.4.2.1. Semantics and Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#Import_Calls">8.4.3. Import Calls</a></li>
</ul>
</li>
<li><a href="expressions.html#compile-time-expressions">8.5. Compile-Time Expressions</a></li>
</ul>
</li>
<li><a href="#_statements">9. Statements</a>
<ul class="sectlevel2">
<li><a href="#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a>
<ul class="sectlevel3">
<li><a href="#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></li>
<li><a href="#_variable-statement">9.1.2. Variable Statement</a></li>
<li><a href="#_if-statement">9.1.3. If Statement</a></li>
<li><a href="#_iteration-statements">9.1.4. Iteration Statements</a></li>
<li><a href="#_return-statement">9.1.5. Return Statement</a></li>
<li><a href="#_with-statement">9.1.6. With Statement</a></li>
<li><a href="#_switch-statement">9.1.7. Switch Statement</a></li>
<li><a href="#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></li>
<li><a href="#_debugger-statement">9.1.9. Debugger Statement</a></li>
</ul>
</li>
<li><a href="#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a>
<ul class="sectlevel3">
<li><a href="#_let">9.2.1. Let</a></li>
<li><a href="#_const">9.2.2. Const</a></li>
<li><a href="#_for-of-statement">9.2.3. <code>for &#8230;&#8203; of</code> statement</a></li>
<li><a href="#_import-statement">9.2.4. Import Statement</a>
<ul class="sectlevel4">
<li><a href="#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></li>
<li><a href="#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></li>
</ul>
</li>
<li><a href="#_export-statement">9.2.5. Export Statement</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_annotations">10. Annotations</a>
<ul class="sectlevel2">
<li><a href="annotations.html#_introduction-2">10.1. Introduction</a>
<ul class="sectlevel3">
<li><a href="annotations.html#_syntax-13">10.1.1. Syntax</a></li>
<li><a href="annotations.html#_properties-7">10.1.2. Properties</a></li>
<li><a href="annotations.html#_element-specific-annotations">10.1.3. Element-Specific Annotations</a></li>
<li><a href="annotations.html#_general-annotations">10.1.4. General Annotations</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_idebug">10.1.4.1. IDEBUG</a></li>
</ul>
</li>
<li><a href="annotations.html#idebug-syntax">10.1.5. Syntax</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_semantics-11">10.1.5.1. Semantics</a></li>
<li><a href="annotations.html#_suppress-warnings">10.1.5.2. Suppress Warnings</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_declaration-of-annotations">10.2. Declaration of Annotations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_extended-fetaures">11. Extended Fetaures</a>
<ul class="sectlevel2">
<li><a href="extended_fetaures.html#_array-and-object-destructuring">11.1. Array and Object Destructuring</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_syntax-14">11.1.1. Syntax</a></li>
<li><a href="extended_fetaures.html#_semantics-12">11.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_dependency-injection">11.2. Dependency Injection</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_di-components-and-injectors">11.2.1. DI Components and Injectors</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_dicomponent-relations">11.2.1.1. DIComponent Relations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_binders-and-bindings">11.2.2. Binders and Bindings</a></li>
<li><a href="extended_fetaures.html#_injection-points">11.2.3. Injection Points</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_field-injection">11.2.3.1. Field Injection</a></li>
<li><a href="extended_fetaures.html#_constructor-injection">11.2.3.2. Constructor Injection</a></li>
<li><a href="extended_fetaures.html#_method-injection">11.2.3.3. Method Injection</a>
<ul class="sectlevel5">
<li><a href="extended_fetaures.html#_provider">11.2.3.3.1. Provider</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_n4js-di-life-cycle-and-scopes">11.2.4. N4JS DI Life Cycle and Scopes</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_injection-cylces">11.2.4.1. Injection Cylces</a></li>
<li><a href="extended_fetaures.html#_default-scope">11.2.4.2. Default Scope</a></li>
<li><a href="extended_fetaures.html#_singleton-scope">11.2.4.3. Singleton Scope</a></li>
<li><a href="extended_fetaures.html#_per-injection-chain-singleton">11.2.4.4. Per Injection Chain Singleton</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_validation-of-callsites-targeting-n4injector-methods">11.2.5. Validation of callsites targeting N4Injector methods</a></li>
<li><a href="extended_fetaures.html#_n4js-di-annotations">11.2.6. N4JS DI Annotations</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_n4js-di-generateinjector">11.2.6.1. N4JS DI @GenerateInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-withparentinjector">11.2.6.2. N4JS DI @WithParentInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-usebinder">11.2.6.3. N4JS DI @UseBinder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-binder">11.2.6.4. N4JS DI @Binder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-bind">11.2.6.5. N4JS DI @Bind</a></li>
<li><a href="extended_fetaures.html#_n4js-di-provides">11.2.6.6. N4JS DI @Provides</a></li>
<li><a href="extended_fetaures.html#_n4js-di-inject">11.2.6.7. N4JS DI @Inject</a></li>
<li><a href="extended_fetaures.html#_n4js-di-singleton">11.2.6.8. N4JS DI @Singleton</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_test-support">11.3. Test Support</a></li>
<li><a href="extended_fetaures.html#_polyfill-definitions">11.4. Polyfill Definitions</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_runtime-polyfill-definitions">11.4.1. Runtime Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_static-polyfill-definitions">11.4.2. Static Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_transpiling-static-polyfilled-classes">11.4.3. Transpiling static polyfilled classes</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_components">12. Components</a>
<ul class="sectlevel2">
<li><a href="components.html#_overview-2">12.1. Overview</a></li>
<li><a href="components.html#Component_Types">12.2. Component Types</a>
<ul class="sectlevel3">
<li><a href="components.html#_libraries">12.2.1. Libraries</a></li>
<li><a href="components.html#_runtime-environment-and-runtime-libraries">12.2.2. Runtime Environment and Runtime Libraries</a></li>
<li><a href="components.html#_tests">12.2.3. Tests</a></li>
<li><a href="components.html#_type-definitions">12.2.4. Type Definitions</a></li>
</ul>
</li>
<li><a href="components.html#package-json">12.3. Package.json File</a>
<ul class="sectlevel3">
<li><a href="components.html#_basic-properties">12.3.1. Basic Properties</a></li>
<li><a href="components.html#_n4js-properties">12.3.2. N4JS Properties</a></li>
<li><a href="components.html#_constraints">12.3.3. Constraints</a></li>
</ul>
</li>
<li><a href="components.html#_support-for-npm-scopes">12.4. Support for NPM Scopes</a></li>
<li><a href="components.html#sec:N4JS-Type-Definitions">12.5. N4JS Type Definitions</a>
<ul class="sectlevel3">
<li><a href="components.html#_specify-type-definition">12.5.1. Specify Type Definition</a></li>
<li><a href="components.html#_name-conventions">12.5.2. Name Conventions</a></li>
<li><a href="components.html#_version-conventions">12.5.3. Version Conventions</a>
<ul class="sectlevel4">
<li><a href="components.html#_define-a-new-type-definition-package">12.5.3.1. Define a New Type Definition Package</a></li>
<li><a href="components.html#_using-a-type-definition-package">12.5.3.2. Using a Type Definition Package</a></li>
<li><a href="components.html#_rational">12.5.3.3. Rational</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_modules">12.6. Modules</a></li>
<li><a href="components.html#_api-and-implementation-component">12.7. API and Implementation Component</a>
<ul class="sectlevel3">
<li><a href="components.html#_execution-of-api-and-implementation-components">12.7.1. Execution of API and Implementation Components</a></li>
<li><a href="components.html#_api-and-implementation-with-di">12.7.2. API and Implementation With DI</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="plainjs.html#_plainjs">13. PlainJS</a>
<ul class="sectlevel2">
<li><a href="plainjs.html#_type-inference-and-validation-for-plain-js">13.1. Type Inference and Validation for Plain JS</a></li>
<li><a href="plainjs.html#_external-declarations">13.2. External Declarations</a>
<ul class="sectlevel3">
<li><a href="plainjs.html#_declaring-externals">13.2.1. Declaring externals</a></li>
<li><a href="plainjs.html#_instantiating-external-classes">13.2.2. Instantiating external classes</a></li>
<li><a href="plainjs.html#_implementation-of-external-declarations">13.2.3. Implementation of External Declarations</a></li>
<li><a href="plainjs.html#_example">13.2.4. Example</a></li>
</ul>
</li>
<li><a href="plainjs.html#_global-definitions">13.3. Global Definitions</a></li>
<li><a href="plainjs.html#_runtime-definitions">13.4. Runtime Definitions</a></li>
<li><a href="plainjs.html#_applying-polyfills">13.5. Applying Polyfills</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_jsdoc-2">14. JSDoc</a>
<ul class="sectlevel2">
<li><a href="jsdoc.html#_general-n4jsdoc-features">14.1. General N4JSDoc Features</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_provided-inline-tags">14.1.1. Provided Inline Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__code">14.1.1.1. @code</a></li>
<li><a href="jsdoc.html#jsdoc_tag__link">14.1.1.2. @link</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-user-projects">14.2. N4JSdoc for User Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_standard-tags">14.2.1. Standard Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#_-author">14.2.1.1. @author</a></li>
<li><a href="jsdoc.html#jsdoc_tag_param">14.2.1.2. @param</a></li>
<li><a href="jsdoc.html#jsdoc_tag_return">14.2.1.3. @return</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_test-related-tags">14.2.2. Test Related Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__testee">14.2.2.1. @testee</a></li>
<li><a href="jsdoc.html#jsdoc_tag__testeeFromType">14.2.2.2. @testeeFromType</a></li>
<li><a href="jsdoc.html#_testeeType_and__testeeMember">14.2.2.3. @testeeType and @testeeMember</a></li>
<li><a href="jsdoc.html#jsdoc_tag_reqid_in_Tests">14.2.2.4. @reqid in Tests</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-api-and-implementation-projects">14.3. N4JSDoc for API and Implementation Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#jsdoc_tag__apiNote">14.3.1. @apiNote</a></li>
<li><a href="jsdoc.html#API_Project_Tags">14.3.2. API Project Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag_apiState">14.3.2.1. @apiState</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="jsx.html#_jsx">15. JSX</a>
<ul class="sectlevel2">
<li><a href="jsx.html#_jsx-support">15.1. JSX Support</a></li>
<li><a href="jsx.html#_jsx-backend">15.2. JSX Backend</a></li>
</ul>
</li>
<li><a href="grammars.html#_grammars">16. Grammars</a>
<ul class="sectlevel2">
<li><a href="grammars.html#_type-expressions-grammar">16.1. Type Expressions Grammar</a></li>
<li><a href="grammars.html#_n4js-language-grammar">16.2. N4JS Language Grammar</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_jsobjects">17. JSObjects</a>
<ul class="sectlevel2">
<li><a href="jsobjects.html#_object">17.1. Object</a></li>
<li><a href="jsobjects.html#_string">17.2. String</a></li>
<li><a href="jsobjects.html#_boolean">17.3. Boolean</a></li>
<li><a href="jsobjects.html#_number">17.4. Number</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#_static-attributes">17.4.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#function">17.5. Function</a></li>
<li><a href="jsobjects.html#_error">17.6. Error</a></li>
<li><a href="jsobjects.html#_array">17.7. Array</a></li>
<li><a href="jsobjects.html#_date">17.8. Date</a></li>
<li><a href="jsobjects.html#_math">17.9. Math</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#static-attributes-1">17.9.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_regexp">17.10. RegExp</a></li>
<li><a href="jsobjects.html#_json">17.11. JSON</a></li>
</ul>
</li>
<li><a href="n4js_objects.html#_n4js-objects">18. N4JS Objects</a>
<ul class="sectlevel2">
<li><a href="n4js_objects.html#_reflection-model">18.1. Reflection Model</a></li>
<li><a href="n4js_objects.html#_error-types">18.2. Error Types</a>
<ul class="sectlevel3">
<li><a href="n4js_objects.html#_n4apinotimplemented">18.2.1. N4ApiNotImplemented</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="appendix_a_acronyms.html#_acronyms">Appendix A: Acronyms</a></li>
<li><a href="appendix_b_license.html#sec:License">Appendix B: License</a></li>
<li><a href="appendix_c_bibliography.html#_bibliography">Appendix C: Bibliography</a></li>
</ul>
</div>
</div>
<div id="content"><div class="sect1">
<h2 id="_statements"><a class="anchor" href="#_statements"></a><a class="link" href="#_statements">9. Statements</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>For all statements, we define the following pseudo properties:</p>
</div>
<div class="openblock language-n4js">
<div class="content">
<div class="dlist">
<dl>
<dt class="hdlist1"><code>containingFunction</code> </dt>
<dd>
<p>The function or method in which the statement is (indirectly) contained, this may be null.</p>
</dd>
<dt class="hdlist1"><code>containingClass</code> </dt>
<dd>
<p>The class in which the statement is (indirectly) contained, this may be null.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="paragraph">
<p>The expressions and statements are ordered, at first describing the constructs available in the 5th edition of ECMA-262
referred to as  [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>] in the following.
The grammar snippets already use newer constructs in some cases.</p>
</div>
<div class="sect2 language-n4js">
<h3 id="_ecmascript-5-statements"><a class="anchor" href="#_ecmascript-5-statements"></a><a class="link" href="#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a></h3>
<div class="paragraph">
<p>N4JS supports the same statements as
ECMAScript. Some of these statements are enhanced with annotations <a href="annotations.html#_annotations">Annotations</a> and type information.</p>
</div>
<div class="paragraph">
<p>Although some statements may return a value which can be used via certain constructs such as <code>eval</code>), no type is inferred for any statement.
The compiler will always create a warning if a statement is used instead of an expression.</p>
</div>
<div class="paragraph">
<p>The following sections, therefore, do not define how to infer types for statement but how types and type annotations
are used in these statements and the specific type constraints for a given statement.</p>
</div>
<div class="paragraph">
<p>All syntax definitions taken from  [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>]  are repeated here for convenience reasons and in order to define temporary variables for simplifying constraint definitions.
If non-terminals are not defined here, the definition specified in  [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>]   is to be used.</p>
</div>
<div class="sect3">
<h4 id="_function-or-field-accessor-bodies"><a class="anchor" href="#_function-or-field-accessor-bodies"></a><a class="link" href="#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></h4>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-126"></a><strong>Req. IDE-126:</strong> <a href="#Req-IDE-126">Dead Code</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For all statements in a function or field accessor (getter/setter) body, the following constraints must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Statements appearing directly after return, throw, break, or continue statements (in the same block) are considered to be dead code and a warning is issued in these cases.</p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_variable-statement"><a class="anchor" href="#_variable-statement"></a><a class="link" href="#_variable-statement">9.1.2. Variable Statement</a></h4>
<h5 id="variable-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>A var statement can declare the type of the variable with a type
reference. This is described with the following grammar similar to
[<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.2, p.p.87)</a>]:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">VariableStatement &lt;In, Yield&gt;:
    =&gt;({VariableStatement}
        'var'
    )
    varDeclsOrBindings+=VariableDeclarationOrBinding&lt;In,Yield,false&gt; (',' varDeclsOrBindings+=VariableDeclarationOrBinding&lt;In,Yield,false&gt;)* Semi
;

VariableDeclarationOrBinding &lt;In, Yield, OptionalInit&gt;:
        VariableBinding&lt;In,Yield,OptionalInit&gt;
    |   VariableDeclaration&lt;In,Yield,true&gt;
;

VariableBinding &lt;In, Yield, OptionalInit&gt;:
    =&gt; pattern=BindingPattern&lt;Yield&gt; (
            &lt;OptionalInit&gt; ('=' expression=AssignmentExpression&lt;In,Yield&gt;)?
        |   &lt;!OptionalInit&gt; '=' expression=AssignmentExpression&lt;In,Yield&gt;
    )
;

VariableDeclaration &lt;In, Yield, AllowType&gt;:
    {VariableDeclaration} VariableDeclarationImpl&lt;In,Yield,AllowType&gt;;

fragment VariableDeclarationImpl &lt;In, Yield, AllowType&gt;*:
    annotations+=Annotation*
    (
        &lt;AllowType&gt; =&gt;(
            name=BindingIdentifier&lt;Yield&gt; ColonSepTypeRef?
        ) ('=' expression=AssignmentExpression&lt;In,Yield&gt;)?
    |   &lt;!AllowType&gt; =&gt;(
        name=BindingIdentifier&lt;Yield&gt;
        ) ('=' expression=AssignmentExpression&lt;In,Yield&gt;)?
    )
;</code></pre>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 94. Variable Statement</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var any: any;
// any.type := any

var anyNull = null;
// anyNull.type := any

var s: string;
// s.type := string

var init = "Hi";
// init.type := string

const MESSAGE = "Hello World";
// MESSAGE.type := string</code></pre>
</div>
</div>
</div>
</div>
<h5 id="variable-statement-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>From a model and type inference point of view, variable and constant statements and declarations are similar except that the pseudo property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi></math> is set to false for variables and true for constants.
Also see exported variable statement (<a href="#_export-statement">Export Statement</a>) and constant statement and declaration (<a href="#_const">Const</a>).</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-127"></a><strong>Req. IDE-127:</strong> <a href="#Req-IDE-127">Variable declaration</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given variable declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi></math>, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The type of the initializer expression must conform to the declared type:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>≠</mo><mstyle mathvariant="monospace"><mtext>null</mtext></mstyle><mo>∧</mo><mi>d</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>≠</mo><mstyle mathvariant="monospace"><mtext>null</mtext></mstyle></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>→</mo><mi>Γ</mi><mo>⊢</mo><mi>d</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>Γ</mi><mo>⊢</mo><mi>d</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></math></p>
</div>
</li>
<li>
<p>The initializer expression should not contain a reference to <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi></math> except where the reference is contained in a class expression or function expression and
the class is not immediately initialized or the function is not immediately invoked.
In these cases, the code is executed later and the self-reference is not a problem.<br>
To clarify: <em>should not</em> means that only a warning will be produced.</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// not ok (simple case)
var n = n + 1;

// ok (class expression not fully supported)
// var cls1 = class { static sfield1 = "hello"; field2 = cls1.sfield1; };

// not ok, immediately instantiated (class expression not fully supported)
// var cls2 = new class { field1 = "hello"; field2 = cls2.field1; };

// ok
var fun1 = function() : number { var x = fun1; return -42; };

// not ok, immediately invoked
var fun2 = function() : number { var x = fun2;  return -42; }();</code></pre>
</div>
</div>
<div class="paragraph">
<p>The variable statement may contain array or object destructuring patterns, see <a href="extended_fetaures.html#_array-and-object-destructuring">Array and Object Destructuring</a> for details.</p>
</div>
</div>
</div>
<h5 id="variable-statement-type-inference" class="discrete">Type Inference</h5>
<div class="paragraph">
<p>The type of a variable is the type of its declaration:</p>
</div>
<div class="openblock">
<div class="content">

</div>
</div>
<div class="paragraph">
<p>The type of a variable declaration is either the declared type or the inferred type of the initializer expression:</p>
</div>
<div class="openblock">
<div class="content">

</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_if-statement"><a class="anchor" href="#_if-statement"></a><a class="link" href="#_if-statement">9.1.3. If Statement</a></h4>
<h5 id="if-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.5, p.p.89)</a>]</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">IfStatement &lt;Yield&gt;:
    'if' '(' expression=Expression&lt;In=true,Yield&gt; ')'
    ifStmt=Statement&lt;Yield&gt;
    (=&gt; 'else' elseStmt=Statement&lt;Yield&gt;)?;</code></pre>
</div>
</div>
<h5 id="if-statement-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>There are no specific constraints defined for the condition, the ECMAScript operation <code>ToBoolean</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.2, p.p.43)</a>] is used to convert any type to boolean.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-128"></a><strong>Req. IDE-128:</strong> <a href="#Req-IDE-128">If Statement</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>In N4JS, the expression of an if statement must not evaluate to <code>void</code>.
If the expressions is a function call in particular, the called function must not be declared to return <code>void</code>.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_iteration-statements"><a class="anchor" href="#_iteration-statements"></a><a class="link" href="#_iteration-statements">9.1.4. Iteration Statements</a></h4>
<h5 id="iterations-statements-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.6, p.p.90ff)</a>]</p>
</div>
<div class="paragraph">
<p>The syntax already considers the for-of style described in <a href="#_for-of-statement"><code>for &#8230;&#8203; of</code> statement</a>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">IterationStatement &lt;Yield&gt;:
        DoStatement&lt;Yield&gt;
    |   WhileStatement&lt;Yield&gt;
    |   ForStatement&lt;Yield&gt;
;

DoStatement &lt;Yield&gt;: 'do' statement=Statement&lt;Yield&gt; 'while' '(' expression=Expression&lt;In=true,Yield&gt; ')' =&gt; Semi?;
WhileStatement &lt;Yield&gt;: 'while' '(' expression=Expression&lt;In=true,Yield&gt; ')' statement=Statement&lt;Yield&gt;;

ForStatement &lt;Yield&gt;:
    {ForStatement} 'for' '('
    (
        // this is not in the spec as far as I can tell, but there are tests that rely on this to be valid JS
            =&gt;(initExpr=LetIdentifierRef forIn?='in' expression=Expression&lt;In=true,Yield&gt; ')')
        |   (   -&gt;varStmtKeyword=VariableStatementKeyword
                (
                        =&gt;(varDeclsOrBindings+=BindingIdentifierAsVariableDeclaration&lt;In=false,Yield&gt; (forIn?='in' | forOf?='of') -&gt;expression=AssignmentExpression&lt;In=true,Yield&gt;?)
                    |   varDeclsOrBindings+=VariableDeclarationOrBinding&lt;In=false,Yield,OptionalInit=true&gt;
                        (
                                (',' varDeclsOrBindings+=VariableDeclarationOrBinding&lt;In=false,Yield,false&gt;)* ';' expression=Expression&lt;In=true,Yield&gt;? ';' updateExpr=Expression&lt;In=true,Yield&gt;?
                            |   forIn?='in' expression=Expression&lt;In=true,Yield&gt;?
                            |   forOf?='of' expression=AssignmentExpression&lt;In=true,Yield&gt;?
                        )
                )
            |   initExpr=Expression&lt;In=false,Yield&gt;
                (
                        ';' expression=Expression&lt;In=true,Yield&gt;? ';' updateExpr=Expression&lt;In=true,Yield&gt;?
                    |   forIn?='in' expression=Expression&lt;In=true,Yield&gt;?
                    |   forOf?='of' expression=AssignmentExpression&lt;In=true,Yield&gt;?
                )
            |   ';' expression=Expression&lt;In=true,Yield&gt;? ';' updateExpr=Expression&lt;In=true,Yield&gt;?
            )
        ')'
    ) statement=Statement&lt;Yield&gt;
;

ContinueStatement &lt;Yield&gt;: {ContinueStatement} 'continue' (label=[LabelledStatement|BindingIdentifier&lt;Yield&gt;])? Semi;
BreakStatement &lt;Yield&gt;: {BreakStatement} 'break' (label=[LabelledStatement|BindingIdentifier&lt;Yield&gt;])? Semi;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Since <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mfenced close=")" open="("><mi>s</mi></mfenced></math> are <code>VariableStatement</code>s as described in <a href="#_variable-statement">Variable Statement</a>, the declared variables can be type annotated.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title=""></i>
</td>
<td class="content">
Using for-in is not recommended, instead <code>_each</code> should be used.
</td>
</tr>
</table>
</div>
<h5 id="iterations-statements-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>There are no specific constraints defined for the condition, the
ECMAScript operation <code>ToBoolean</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S9.2, p.p.43)</a>] is used to convert any type to boolean.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-129"></a><strong>Req. IDE-129:</strong> <a href="#Req-IDE-129">For-In-Statement Constraints</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> the following conditions must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The type of the expression must be conform to object:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi><mo>⊢</mo><mi>f</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>union</mtext><mtext>Object,string,ArgumentType</mtext></mstyle></math></p>
</li>
<li>
<p>Either a new loop variable must be declared or an rvalue must be provided as init expression:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><mfenced close=")" open="("><mrow><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mi>i</mi><mi>s</mi><mi>R</mi><mi>V</mi><mi>a</mi><mi>l</mi><mi>u</mi><mi>e</mi><mfenced close=")" open="("><mrow><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mi>r</mi></mrow></mfenced></mrow></mfenced></math></p>
</li>
<li>
<p>The type of the loop variable must be a string (or a super type of string, i.e. any):</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd/><mtd><mrow><mo>(</mo><mrow><mi>f</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mi>Γ</mi><mo>⊢</mo><mi>f</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mo>)</mo></mrow></mrow></mtd></mtr><mtr><mtd><mo>∨</mo></mtd><mtd><mrow><mo>(</mo><mrow><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo>)</mo></mrow></mrow></mtd></mtr></mtable></math>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect3 language-n4js">
<h4 id="_return-statement"><a class="anchor" href="#_return-statement"></a><a class="link" href="#_return-statement">9.1.5. Return Statement</a></h4>
<h5 id="return-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>The returns statement is defined as in [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.9, p.p.93)</a>] with</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ReturnStatement &lt;Yield&gt;:
    'return' (expression=Expression&lt;In=true,Yield&gt;)? Semi;</code></pre>
</div>
</div>
<h5 id="return-statement-semantics" class="discrete">Semantics</h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-130"></a><strong>Req. IDE-130:</strong> <a href="#Req-IDE-130">Return statement</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Expected type of expression in a return statement must be a sub type of the return type of the enclosing function:</p>
<div class="openblock">
<div class="content">

</div>
</div>
<div class="paragraph">
<p>Note that the expression may be evaluated to <code>void</code>.</p>
</div>
</li>
<li>
<p>If enclosing function is declared to return <code>void</code>, then either</p>
<div class="ulist">
<ul>
<li>
<p>no return statement must be defined</p>
</li>
<li>
<p>return statement has no expression</p>
</li>
<li>
<p>type of expression of return statement is <code>void</code></p>
</li>
</ul>
</div>
</li>
<li>
<p>If enclosing function is declared to to return a type different from <code>void</code>, then</p>
<div class="ulist">
<ul>
<li>
<p>all return statements must have a return expression</p>
</li>
<li>
<p>all control flows must either end with a return or throw statement</p>
</li>
</ul>
</div>
</li>
<li>
<p>Returns statements must be enclosed in a function.
A return statement, for example, must not be a top-level statement.</p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_with-statement"><a class="anchor" href="#_with-statement"></a><a class="link" href="#_with-statement">9.1.6. With Statement</a></h4>
<h5 id="with-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>The with statement is not allowed in N4JS, thus an error is issued.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">WithStatement &lt;Yield&gt;:
    'with' '(' expression=Expression&lt;In=true,Yield&gt; ')'
    statement=Statement&lt;Yield&gt;;</code></pre>
</div>
</div>
<h5 id="with-statement-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>N4JS is based on strict mode and the with statement is not allowed in
strict mode, cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.10.1, p.p.94)</a>].</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-131"></a><strong>Req. IDE-131:</strong> <a href="#Req-IDE-131">With Statement</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>With statements are not allowed in N4JS or strict mode.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_switch-statement"><a class="anchor" href="#_switch-statement"></a><a class="link" href="#_switch-statement">9.1.7. Switch Statement</a></h4>
<h5 id="switch-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.11, p.p.94ff)</a>]</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">SwitchStatement &lt;Yield&gt;:
    'switch' '(' expression=Expression&lt;In=true,Yield&gt; ')' '{'
    (cases+=CaseClause&lt;Yield&gt;)*
    ((cases+=DefaultClause&lt;Yield&gt;)
    (cases+=CaseClause&lt;Yield&gt;)*)? '}'
;

CaseClause &lt;Yield&gt;: 'case' expression=Expression&lt;In=true,Yield&gt; ':' (statements+=Statement&lt;Yield&gt;)*;
DefaultClause &lt;Yield&gt;: {DefaultClause} 'default' ':' (statements+=Statement&lt;Yield&gt;)*;</code></pre>
</div>
</div>
<h5 id="switch-statement-semantics" class="discrete">Semantics</h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-132"></a><strong>Req. IDE-132:</strong> <a href="#Req-IDE-132">Switch Constraints</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given switch statement <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi></math>, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>For all cases <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mo>∈</mo><mi>s</mi><mo>.</mo><mi>c</mi><mi>a</mi><mi>s</mi><mi>e</mi><mi>s</mi></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi></math>===<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi></math> must be valid according to the constraints defined in <a href="expressions.html#_equality-expression">Equality Expression</a>.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_throw-try-and-catch-statements"><a class="anchor" href="#_throw-try-and-catch-statements"></a><a class="link" href="#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></h4>
<h5 id="throw-try-catch-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.13/14, p.p.96ff)</a>]</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ThrowStatement &lt;Yield&gt;:
    'throw' expression=Expression&lt;In=true,Yield&gt; Semi;

TryStatement &lt;Yield&gt;:
    'try' block=Block&lt;Yield&gt;
    ((catch=CatchBlock&lt;Yield&gt; finally=FinallyBlock&lt;Yield&gt;?) | finally=FinallyBlock&lt;Yield&gt;)
;

CatchBlock &lt;Yield&gt;: {CatchBlock} 'catch' '(' catchVariable=CatchVariable&lt;Yield&gt; ')' block=Block&lt;Yield&gt;;

CatchVariable &lt;Yield&gt;:
        =&gt;bindingPattern=BindingPattern&lt;Yield&gt;
    |   name=BindingIdentifier&lt;Yield&gt;
;

FinallyBlock &lt;Yield&gt;: {FinallyBlock} 'finally' block=Block&lt;Yield&gt;;</code></pre>
</div>
</div>
<div class="paragraph">
<p>There must be not type annotation for the catch variable, as this would lead to the wrong assumption that a type can be specified.</p>
</div>
<h5 id="throw-try-catch-type-inference" class="discrete">Type Inference</h5>
<div class="paragraph">
<p>The type of the catch variable is always assumed to be <code>any</code>.</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mi>c</mi><mi>a</mi><mi>t</mi><mi>c</mi><mi>h</mi><mi>B</mi><mi>l</mi><mi>o</mi><mi>c</mi><mi>k</mi><mo>.</mo><mi>c</mi><mi>a</mi><mi>t</mi><mi>c</mi><mi>h</mi><mi>V</mi><mi>a</mi><mi>r</mi><mi>i</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mi>:</mi><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mrow></mfrac></math>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_debugger-statement"><a class="anchor" href="#_debugger-statement"></a><a class="link" href="#_debugger-statement">9.1.9. Debugger Statement</a></h4>
<h5 id="debugger-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S12.15, p.p.97ff)</a>])</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">DebuggerStatement: {DebuggerStatement} 'debugger' Semi;</code></pre>
</div>
</div>
<h5 id="debugger-statement--semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>na</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_ecmascript-6-statements"><a class="anchor" href="#_ecmascript-6-statements"></a><a class="link" href="#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a></h3>
<div class="paragraph">
<p>N4JS export and import statements are similar to ES6 with some minor d ifferences which are elaborated on below.</p>
</div>
<div class="sect3">
<h4 id="_let"><a class="anchor" href="#_let"></a><a class="link" href="#_let">9.2.1. Let</a></h4>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.13.2.1)</a>], also <a href="http://www.2ality.com/2015/02/es6-scoping.html">Rauschmayer, 2ality: <strong>Variables and scoping in ECMAScript 6</strong></a></p>
</div>
</div>
<div class="sect3">
<h4 id="_const"><a class="anchor" href="#_const"></a><a class="link" href="#_const">9.2.2. Const</a></h4>
<div class="paragraph">
<p>Cf. [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.13.2.1)</a>], also <a href="http://www.2ality.com/2015/02/es6-scoping.html">Rauschmayer, 2ality: <strong>Variables and scoping in ECMAScript 6</strong></a></p>
</div>
<div class="paragraph">
<p>Additionally to the <code>var</code> statement, the <code>const</code> statement is supported.
It allows for declaring variables which must be assigned to a value in the declaration and their value must not change.
That is to say that constants are not allowed to be on the left-hand side of other assignments.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ConstStatement returns VariableStatement: 'const' varDecl+=ConstDeclaration ( ',' varDecl+=ConstDeclaration )* Semi;

ConstDeclaration returns VariableDeclaration: typeRef=TypeRef? name=IDENTIFIER const?='=' expression=AssignmentExpression;</code></pre>
</div>
</div>
<h5 id="const-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>A const variable statement is more or less a normal variable statement (see <a href="#_variable-statement">Variable Statement</a>), except that all variables declared by that
statement are not writable (cf. <a href="expressions.html#Req-IDE-121">[Req-IDE-121]</a>).
This is similar to constant data fields (cf. <a href="classifiers.html#_assignment-modifiers">Assignment Modifiers</a>).</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-133"></a><strong>Req. IDE-133:</strong> <a href="#Req-IDE-133">Writability of const variables</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>All variable declarations of a const variable statement
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>S</mi><mi>t</mi><mi>m</mi><mi>t</mi></math> are not writeable:
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>v</mi><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mo>∈</mo><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>S</mi><mi>t</mi><mi>m</mi><mi>t</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>:</mi><mo>¬</mo><mi>v</mi><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mo>.</mo><mi>w</mi><mi>r</mi><mi>i</mi><mi>t</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi></math></p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_for-of-statement"><a class="anchor" href="#_for-of-statement"></a><a class="link" href="#_for-of-statement">9.2.3. <code>for &#8230;&#8203; of</code> statement</a></h4>
<div class="paragraph">
<p>ES6 introduced a new form of <code>for</code> statement: <code>for &#8230;&#8203; of</code> to iterate over the elements of an  <code>Iterable</code>, cf. <a href="#_iterablen">[_iterablen]</a>.</p>
</div>
<h5 id="for-of-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>See <a href="#_iteration-statements">Iteration Statements</a></p>
</div>
<h5 id="for-of-statement-semantics" class="discrete">Semantics</h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-134"></a><strong>Req. IDE-134:</strong> <a href="#Req-IDE-134">for &#8230;&#8203; of statement</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> the following conditions must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The value provided after <code>of</code> in a <code>for &#8230;&#8203; of</code> statement must be a subtype of <code>Iterable&lt;?&gt;</code>.</p>
</li>
<li>
<p>Either a new loop variable must be declared or an rvalue must be provided as init expression:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><mfenced close=")" open="("><mrow><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mi>r</mi><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mi>i</mi><mi>s</mi><mi>R</mi><mi>V</mi><mi>a</mi><mi>l</mi><mi>u</mi><mi>e</mi><mfenced close=")" open="("><mrow><mi>f</mi><mo>.</mo><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>E</mi><mi>x</mi><mi>p</mi><mi>r</mi></mrow></mfenced></mrow></mfenced></math></p>
</li>
<li>
<p>If a new variable <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi></math> is declared before <code>of</code> and it has a declared type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math>, the value provided after must be a subtype of <code>Iterable&lt;?extendsT&gt;</code>.
If <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi></math> does not have a declared type, the type of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi></math> is inferred to the type of the first type argument of the actual type of the value provided after <code>of</code>.</p>
</li>
<li>
<p>If a previously-declared variable is referenced before with a declared or inferred type of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math>, the value provided after <code>of</code> must be a subtype of <code>Iterable&lt;?extendsT&gt;</code>.</p>
</li>
</ol>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
<code>Iterable</code> is structurally typed on definition-site so non-N4JS types can meet the above requirements by simply implementing the only method in interface <code>Iterable</code> (with a correct return type).
</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
The first of the above constraints (the type required by the ’of’ part in a <code>for &#8230;&#8203; of</code> loop is <code>Iterable</code>) was changed during the definition of ECMAScript 6.
This is implemented differently in separate implementations and even in different versions of the same implementation (for instance in different versions of V8).
Older implementations require an <code>Iterator</code> or accept both <code>Iterator</code> an or <code>Iterable</code>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Requiring an <code>Iterable</code> and not accepting a plain <code>Iterator</code> seems to be the final decision (as of Dec. 2014).
For reference, see abstract operations <code>GetIterator</code> in [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.S7.4.2)</a>] and "CheckIterable" [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.S7.4.1)</a>] and their
application in "ForIn/OfExpressionEvaluation" [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.S13.6.4.8)</a>] and <code>CheckIterable</code> and their application in <code>ForIn/OfExpressionEvaluation</code>.
See also a related blog post <sup class="footnote">[<a id="_footnoteref_53" class="footnote" href="appendix_c_bibliography.html#_footnote_53" title="View footnote.">53</a>]</sup> that is kept up to date with changes to ECMAScript 6:</p>
</div>
<div class="quoteblock">
<blockquote>
<em>ECMAScript 6 has a new loop, for-of. That loop works with iterables. Before we can use it with createArrayIterator(), we need to turn the result into an iterable.</em>
</blockquote>
</div>
<div class="paragraph">
<p>An array or object destructuring pattern may be used left of the <code>of</code>.
This is used to destructure the elements of the <code>Iterable</code> on the right-hand side (not the <code>Iterable</code> itself).
For detais, see <a href="extended_fetaures.html#_array-and-object-destructuring">Array and Object Destructuring</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_import-statement"><a class="anchor" href="#_import-statement"></a><a class="link" href="#_import-statement">9.2.4. Import Statement</a></h4>
<div class="paragraph">
<p>Cf. ES6 import [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.15.2.2)</a>], see also <a href="https://babeljs.io/docs/usage/modules/" class="bare">https://babeljs.io/docs/usage/modules/</a></p>
</div>
<h5 id="import-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>The grammar of import declarations is defined as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ImportDeclaration:
    {ImportDeclaration}
    ImportDeclarationImpl
;

fragment ImportDeclarationImpl*:
    'import' (
        ImportClause importFrom?='from'
    )? module=[types::TModule|ModuleSpecifier] Semi
;

fragment ImportClause*:
        importSpecifiers+=DefaultImportSpecifier (',' ImportSpecifiersExceptDefault)?
    |   ImportSpecifiersExceptDefault
;

fragment ImportSpecifiersExceptDefault*:
        importSpecifiers+=NamespaceImportSpecifier
    |   '{' (importSpecifiers+=NamedImportSpecifier (',' importSpecifiers+=NamedImportSpecifier)* ','?)? '}'
;

NamedImportSpecifier:
        importedElement=[types::TExportableElement|BindingIdentifier&lt;Yield=false&gt;]
    |   importedElement=[types::TExportableElement|IdentifierName] 'as' alias=BindingIdentifier&lt;Yield=false&gt;
;

DefaultImportSpecifier:
    importedElement=[types::TExportableElement|BindingIdentifier&lt;Yield=false&gt;]
;

NamespaceImportSpecifier: {NamespaceImportSpecifier} '*' 'as' alias=BindingIdentifier&lt;false&gt; (declaredDynamic?='+')?;

ModuleSpecifier: STRING;</code></pre>
</div>
</div>
<div class="paragraph">
<p>These are the properties of import declaration which can be specified by the user:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>annotations</code> </dt>
<dd>
<p>Arbitrary annotations, see <a href="annotations.html#_annotations">Annotations</a> and below for details.</p>
</dd>
<dt class="hdlist1"><code>importSpecifiers</code> </dt>
<dd>
<p>The elements to be imported with their names.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Also see compilation as described in <a href="components.html#_modules">Modules</a>, for semantics see <a href="#import-statement-semantics">Import Statement Semantics</a>.</p>
</div>
<div class="exampleblock">
<div class="title">Example 95. Import</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import A from "p/A"
import {C,D,E} from "p/E"
import * as F from "p/F"
import {A as G} from "p/G"
import {A as H, B as I} from "p/H"</code></pre>
</div>
</div>
</div>
</div>
<h5 id="import-statement-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>Import statements are used to import identifiable elements from another module.
Identifiable elements are</p>
</div>
<div class="ulist">
<ul>
<li>
<p>types (via their type declaration), in particular</p>
<div class="ulist">
<ul>
<li>
<p>classifiers (classes, interfaces)</p>
</li>
<li>
<p>functions</p>
</li>
</ul>
</div>
</li>
<li>
<p>variables and constants.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The module to import from is identified by the string literal following keyword <code>from</code>.
This string must be a valid</p>
</div>
<div class="ulist">
<ul>
<li>
<p>complete module specifier <sup class="footnote">[<a id="_footnoteref_54" class="footnote" href="appendix_c_bibliography.html#_footnote_54" title="View footnote.">54</a>]</sup>:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import {A} from "ProjectA/a/b/c/M"</code></pre>
</div>
</div>
</li>
<li>
<p>plain module specifier:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import {A} from "a/b/c/M"</code></pre>
</div>
</div>
</li>
<li>
<p>or project name only, assuming the project defines a main module in its <code>package.json</code> file (using the <code>mainModule</code> package.json property, see <a href="components.html#package-json-mainModule">mainModule</a>):</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import {A} from "ProjectA"</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>For choosing the element to import, there are the exact same options as in ECMAScript6:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>named imports select one or more elements by name, optionally introducing a local alias:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import {C} from "M"
    import {D as MyD} from "M"
    import {E, F as MyF, G, H} from "M"</code></pre>
</div>
</div>
</li>
<li>
<p>namespace imports select all elements of the remote module for import and define a namespace name; the imported elements are then accessed via the namespace name:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import * as N from "M"
    var c: N.C = new N.C();</code></pre>
</div>
</div>
</li>
<li>
<p>default imports select whatever element was exported by the remote module as the default (there can be at most one default export per module):</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import C from "M"</code></pre>
</div>
</div>
</li>
<li>
<p>namespace imports provide access to the default export:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    import * as N from "M"
    var c: N.default = new N.default();</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div class="openblock">
<div class="content">
<div class="paragraph">
<p>The following constraints are defined on a (non-dynamic) import statement <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The imported module needs to be accessible from the current project.</p>
</li>
<li>
<p>The imported declarations need to be accessible from the current module.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>For named imports, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>No declaration must be imported multiple times, even if aliases are used.</p>
</li>
<li>
<p>The names must be unique in the module. They must not conflict with each other or locally declared variables, types, or functions.</p>
</li>
<li>
<p>Declarations imported via named imports are accessible only via used name (or alias) and not via original name directly.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>For wildcard imports, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Only one namespace import can be used per (target) module, even if different namespace name is used.</p>
</li>
<li>
<p>The namespace name must be unique in the module. They must not conflict with each other or locally declared variables, types, or functions.</p>
</li>
<li>
<p>Declarations imported via namespace import are accessible via namespace only and not with original name directly.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>For namespace imports, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If the referenced module is a plain <code>js</code> file, a warning will be created to use the dynamic import instead.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>For default imports, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The referenced module must have a default export.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Cross-cutting constraints:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>No declaration can be imported via named import and namespace import at the same time.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 96. Imports</div>
<div class="content">
<div class="paragraph">
<p>Imports cannot be duplicated:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as A from 'A';
import * as A from 'A';//error, duplicated import statement

import B from 'B';
import B from 'B';//error, duplicated import statement</code></pre>
</div>
</div>
<div class="paragraph">
<p>Given element cannot be imported multiple times:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as A1 from 'A';
import * as A2 from 'A';//error, elements from A already imported in A1

import B from 'B';
import B as B1 from 'B';//error, B/B is already imported as B

import C as C1 from 'C';
import C from 'C';//error, C/C is already imported as C1

import D as D1 from 'D';
import D as D2 from 'D';//error, D/D is already imported as D1

import * as NE from 'E';
import E from 'E';//error, E/E is already imported as NE.E

import F from 'F';
import * as NF from 'F';//error, F/F is already imported as F</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>Names used in imports must not not conflict with each other or local
declarations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as A from 'A1';
import * as A from 'A2';//A is already used as namespace for A1

import B from 'B1';
import B1 as B from 'B2';//B us already used as import B/B1

import C1 as C from 'C1';
import * as C from 'C2'; //C is already used as import C1/C1

import * as D from 'D1';
import D2 as D from 'D2';//D is already used as namespace for D1

import E from 'E';
var E: any; // conflict with named import E/E

import * as F from 'F';
var F: any; // conflict with namespace F</code></pre>
</div>
</div>
<div class="paragraph">
<p>Using named imports, aliases and namespaces allows to refer to mulitple
types of the same name such as  <code>A/A</code>, <code>B/A</code> and <code>C/A</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import A from 'A';// local name A referencess to A/A
import A as B from 'B';//local name B referencess to B/A
import * as C from 'C';//local name C.A referencess to C/A</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>If a declaration has been imported with an alias or namespace, it is not
accessible via its original name:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as B from 'A1';
import A2 as C from 'A2';

var a1_bad: A1;//error, A1/A1 is not directly accessible with original name
var a1_correct: B.A1;// A1/A1 is accessible via namespace B
var a2_bad: A2;//error, A2/A2 is not directly accessible with original name
var a2_correct: C;// A2/A2 is accessible via alias C</code></pre>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="Dynamic_Imports"><a class="anchor" href="#Dynamic_Imports"></a><a class="link" href="#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></h5>
<div class="paragraph">
<p>N4JS extends the ES6 module import in order that modules without a <code>n4jsd</code> or <code>n4js</code> file (plain <code>js</code> modules) can be imported.
This is done by adding <code>+</code> to the name of the named import. This form of compile-time import without type information is not
to be confused with import calls as described in <a href="expressions.html#Import_Calls">Import Calls</a>, which are sometimes referred to as "dynamic import" as well.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-136"></a><strong>Req. IDE-136:</strong> <a href="#Req-IDE-136">Dynamic Import</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> be an import
statement <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> with a dynamic namespace specifier. The
following constraints must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi></math> must not reference an <code>n4js</code> file.</p>
</li>
<li>
<p>If <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi></math> references an <code>n4jsd</code> file, a warning is
to be created.</p>
</li>
<li>
<p>If the file referenced by <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi></math> is not found, an
error is created just as in the static case.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>These constraints define the error level when using dynamic import: we receive no error for <code>js</code>, a warning for <code>n4jsd</code>, and an error for <code>n4js</code> files.
The idea behind these distinct error levels is as follows:<br>
If only a plain <code>js</code> file is available, using the dynamic import is the only way to access elements from the <code>js</code> module.
This might be an unsafe way, but it allows the access and simplifies the first steps.
An <code>n4jsd</code> file may then be made available either by the developer using the <code>js</code> module or by a third-party library.
In this case, we do not want to break existing code.
There is only a warning created in the case of an available <code>n4jsd</code> file and a <code>js</code> file still must be provided by the user.
Having an <code>n4js</code> file is a completely different story; no <code>n4jsd</code> file is required, no <code>js</code> file is needed
(since the transpiler creates one from the <code>n4js</code> file) and there is absolutely no reason to use the module dynamically.</p>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_immutabilaty-of-imports"><a class="anchor" href="#_immutabilaty-of-imports"></a><a class="link" href="#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></h5>
<div class="paragraph">
<p>Imports create always immutable bindings, c.f.
[<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.8.1.1.5)</a>]
<a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-createimportbinding" class="bare">http://www.ecma-international.org/ecma-262/6.0/index.html#sec-createimportbinding</a></p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-137"></a><strong>Req. IDE-137:</strong> <a href="#Req-IDE-137">Immutable Import</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> be a binding to an imported element.
It is an error if</p>
</div>
<div class="ulist">
<ul>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> occurs on the left-hand side as the assignment-target of an assignment expression (this also includes any level in a destructuring pattern on the left-hand side),</p>
</li>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> as a direct argument of a postfix operator (<code>i++</code>/<code>i--</code>),</p>
</li>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> as a direct argument of a <code>delete</code> operator,</p>
</li>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi></math> as a direct argument of the <code>increment</code> or <code>decrement</code> unary operator (<code>i++</code>/<code>i--</code>)</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_export-statement"><a class="anchor" href="#_export-statement"></a><a class="link" href="#_export-statement">9.2.5. Export Statement</a></h4>
<div class="paragraph">
<p>Cf. ES6 import [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.15.2.3)</a>]</p>
</div>
<h5 id="export-statement-syntax" class="discrete">Syntax</h5>
<div class="paragraph">
<p>Grammar of export declarations is defined as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ExportDeclaration:
    {ExportDeclaration}
    ExportDeclarationImpl
;

fragment ExportDeclarationImpl*:
    'export' (
        wildcardExport?='*' ExportFromClause Semi
    |   ExportClause -&gt;ExportFromClause? Semi
    |   exportedElement=ExportableElement
    |   defaultExport?='default' (-&gt;exportedElement=ExportableElement | defaultExportedExpression=AssignmentExpression&lt;In=true,Yield=false&gt; Semi)
    )
;

fragment ExportFromClause*:
    'from' reexportedFrom=[types::TModule|ModuleSpecifier]
;

fragment ExportClause*:
    '{'
        (namedExports+=ExportSpecifier (',' namedExports+=ExportSpecifier)* ','?)?
    '}'
;

ExportSpecifier:
    element=IdentifierRef&lt;Yield=false&gt; ('as' alias=IdentifierName)?
;

ExportableElement:
      N4ClassDeclaration&lt;Yield=false&gt;
    | N4InterfaceDeclaration&lt;Yield=false&gt;
    | N4EnumDeclaration&lt;Yield=false&gt;
    | ExportedFunctionDeclaration&lt;Yield=false&gt;
    | ExportedVariableStatement
;</code></pre>
</div>
</div>
<div class="paragraph">
<p>These are the properties of export declaration, which can be specified by the user:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>exportedElement</code> </dt>
<dd>
<p>The element to be exported, can be a declaration or a variable/const statement.</p>
</dd>
</dl>
</div>
<div class="exampleblock">
<div class="title">Example 97. Export</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">export public class A{}
export interface B{}
export function foo() {}
export var a;
export const c="Hello";</code></pre>
</div>
</div>
</div>
</div>
<h5 id="export-statement-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>With regard to type inference, export statements are not handled at all.
Only the exported element is inferred and the <code>export</code> keyword is ignored.</p>
</div>
<div class="paragraph">
<p>In order to use types defined in other compilation units, these types have to be explicitly imported with an import statement.</p>
</div>
<div class="paragraph">
<p>Imported namespaces cannot be exported.</p>
</div>
<div class="paragraph">
<p>Declared elements (types, variables, functions) are usually only visible outside the declaring module if the elements are exported and imported (by the using module, cf. <a href="#_import-statement">Import Statement</a>).</p>
</div>
<div class="paragraph">
<p>Some special components (runtime environment and libraries, cf. <a href="components.html#_runtime-environment-and-runtime-libraries">Runtime Environment and Runtime Libraries</a>, may export elements globally.
This is done by annotating the export (or the whole module) with <code>@Global</code>, see <a href="plainjs.html#_global-definitions">Global Definitions</a> for details.</p>
</div>
<div class="paragraph">
<p>By adding <code>default</code> after the keyword <code>export</code>, the identifiable element can be exported as ’the default’.
This can then be imported from other modules via default imports (see <a href="#_import-statement">Import Statement</a>).</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 0.9<br>
Last updated 2019-08-08 13:15:33 CEST
</div>
</div>
<!-- ************* docinfo-footer *************************************************************** -->
<div class="Grid social" style="color:#d5dfea">
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <h2>Quick Links</h2>
    <ul>
      <li><a href="../downloads.html">Download</a></li>
      <li><a href="../userguides/index.html">Documentation</a></li>
      <li><a href="https://github.com/eclipse/n4js/">Source</a></li>
      <li><a href="https://github.com/eclipse/n4js/issues">Issues</a></li>
    </ul>
  </div>
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <br/><br/>
    <ul>
      <li><a href="https://www.eclipse.org/forums/index.php/f/365/">Forum</a></li>
      <li><a href="http://n4js.blogspot.de/">Blog</a></li>
      <li><a href="https://dev.eclipse.org/mailman/listinfo/n4js-dev">Mailing List</a></li>
      <li><a href="https://projects.eclipse.org/projects/technology.n4js">Eclipse Project Page</a></li>
      <li><a href="https://twitter.com/n4jsdev">Tweets by n4jsdev</a></li>
    </ul>
  </div>
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <br/><br/>
    <ul>
      <li><a href="http://www.eclipse.org/">Eclipse Home</a></li>
      <li><a href="http://www.eclipse.org/legal/privacy.php">Privacy Policy</a></li>
      <li><a href="http://www.eclipse.org/legal/termsofuse.php">Terms of Use</a></li>
      <li><a href="http://www.eclipse.org/legal/copyright.php">Copyright Agent</a></li>
      <li><a href="http://www.eclipse.org/legal/">Legal</a></li>
    </ul>
  </div>
  <div style="clear: both; height: 0; overflow: hidden;"></div>
</div>

<!-- ************* UI Scripts ************* -->
<script type="text/javascript" src="scripts/back-to-top.js"></script>

<script type="text/javascript" src="scripts/treeview.js"></script>
<script type="text/javascript" src="scripts/toc.js"></script>

<!-- ************* Prism.js Syntax Highlighting ************* -->
<script src="scripts/prism.js"></script>

<script type="text/javascript">
	// Add the 'toclist' id for search function
	$(".toc2 > ul").attr('id', 'toclist');
	// Generate a Search input form
	$("#toclist > li:first-of-type").before('<input type="text" id="pagesearch" onkeyup="search()" placeholder="Search for section...">');
	$("#toclist > li:first-of-type").before('<i id="clear" class="fa fa-times-circle-o"></i>');
	$("#clear").click(function(){
	    $("#pagesearch").val('');
	    search();
	    $('.toc2 > ul').treeView('collapseAll');
	});
	// intialize Treeview.js
	$(".toc2 > ul").treeView();
	// Initialize Scrollspy
</script>
<!-- ************* docinfo-footer *************************************************************** -->
</body>
</html>